HILLSEQ Hill Sequence - CodeChef Solution


Implementation Medium

Python Code:

t=int(input())
for _ in range(t):
    number=int(input())
    arr=list(map(int,input().split()))
    arrL,arrR,dic,maxx,maxx2=[],[],{},0,0
    for num in arr:
        if num in dic:
            dic[num]+=1
            arrL.append(num)
        else:
            dic[num]=1
            arrR.append(num)
        maxx=max(maxx,num)
    for k,v in dic.items():
        if v>2:
            maxx2=v
            break
    if dic[maxx]>1 or maxx2>2:
        print(-1)
    else:
        arrL.sort()
        arrR.sort(reverse=True)
        ans=arrL+arrR
        print(*ans)


Comments

Submit
0 Comments
More Questions

908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar
934A - A Compatible Pair
1618F - Reverse
1684C - Column Swapping
57C - Array
1713D - Tournament Countdown
33A - What is for dinner
810A - Straight A
1433C - Dominant Piranha
633A - Ebony and Ivory
1196A - Three Piles of Candies
299A - Ksusha and Array
448B - Suffix Structures
1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site